// pages/time/time.js
const utils = require('../../utils/util');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    food_start_time_am: '',
    food_end_time_am: '',
    food_start_time_pm: '',
    food_end_time_pm: ''
  },
  bindAmStartTimeChange(e) {
    // console.log(e)
    let that = this;
    this.setData({
      food_start_time_am: e.detail.value
    })
    utils.getAjax(`${app.globalData.apiUrl}/Api/Food/operation_food_time`, res=> {
      if(res.data.code == 1) {
        utils.showToast('时间已提交成功！','success', 1000)
      }
    }, {
      id: 1,
      food_time: that.data.food_start_time_am,
      food_end_time: that.data.food_end_time_am
    })
  },
  bindAmEndTimeChange(e) {
    let that = this;
    this.setData({
      food_end_time_am: e.detail.value
    })
    utils.getAjax(`${app.globalData.apiUrl}/Api/Food/operation_food_time`, res=> {
      if(res.data.code == 1) {
        utils.showToast('时间已提交成功！','success', 1000)
      }
    }, {
      id: 1,
      food_time: that.data.food_start_time_am,
      food_end_time: that.data.food_end_time_am
    })
  },
  bindPmStartTimeChange(e) {
    let that = this;
    this.setData({
      food_start_time_pm: e.detail.value
    })
    utils.getAjax(`${app.globalData.apiUrl}/Api/Food/operation_food_time`, res=> {
      if(res.data.code == 1) {
        utils.showToast('时间已提交成功！','success', 1000)
      }
    }, {
      id: 2,
      food_time: that.data.food_start_time_pm,
      food_end_time: that.data.food_end_time_pm
    })
  },
  bindPmEndTimeChange(e) {
    let that = this;
    this.setData({
      food_end_time_pm: e.detail.value
    })
    utils.getAjax(`${app.globalData.apiUrl}/Api/Food/operation_food_time`, res=> {
      if(res.data.code == 1) {
        utils.showToast('时间已提交成功！','success', 1000)
      }
    }, {
      id: 2,
      food_time: that.data.food_start_time_pm,
      food_end_time: that.data.food_end_time_pm
    })
  },
  // 获取时间
  getTime() {
    let that = this;
    utils.getAjax(`${app.globalData.apiUrl}/Api/Food/ce`,res=> {
      console.log(res)
      that.setData({
        food_start_time_am: res.data[0].food_time,
        food_end_time_am: res.data[0].food_end_time,
        food_start_time_pm: res.data[1].food_time,
        food_end_time_pm: res.data[1].food_end_time
      })
    })
  },
  submit() {
    const that = this;
    utils.getAjax(`${app.globalData.apiUrl}/Api/Food/operation_food_time`, res => {
      console.log(res)
      if(res.data.code == 1) {
        utils.showToast('时间已提交成功！','success', 1000)
      }
    }, {
      food_time: that.data.food_time
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getTime()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})